package com.jjb.www.ui.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import com.hjq.base.BaseDialog;
import com.jjb.www.R;
import com.jjb.www.aop.SingleClick;


/**
 * author : Android
 * time   : 2019/03/20
 * desc   : 通用Dialog
 */
public final class CommonUseDialog {

    public static final class Builder
            extends BaseDialog.Builder<Builder> {
        @Nullable
        private OnListener mListener;
        private final AppCompatTextView tvHint;
        private final AppCompatTextView tvAuthorization;
        private final AppCompatTextView tvCancel;

        public Builder(Context context) {
            super(context);
            setContentView(R.layout.dialog_authorization);
            setAnimStyle(BaseDialog.ANIM_BOTTOM);
            setCancelable(true);
            tvHint = findViewById(R.id.tv_hint);
            tvAuthorization = findViewById(R.id.tv_authorization);
            tvCancel = findViewById(R.id.tv_cancel);
            setOnClickListener(tvAuthorization, tvCancel);
        }

        public Builder setListener(OnListener listener) {
            mListener = listener;
            return this;
        }

        public Builder setLeftContent(String leftContent) {
            tvAuthorization.setText(leftContent);
            return this;
        }

        public Builder setRightContent(String rightContent) {
            tvCancel.setText(rightContent);
            return this;
        }

        /**
         * 设置提示
         */
        public Builder setHint(CharSequence hint) {
            tvHint.setText(hint);
            return this;
        }

        @SingleClick
        @Override
        public void onClick(View view) {
            if (view == tvAuthorization) {
                if (mListener == null) {
                    return;
                }
                dismiss();
                mListener.onCompleted(getDialog());
            } else if (view == tvCancel) {
                if (mListener == null) {
                    return;
                }
                dismiss();
                mListener.onCancel(getDialog());
            }
        }
    }
    public interface OnListener {
        void onCompleted(BaseDialog dialog);
        void onCancel(BaseDialog dialog);
    }
}